AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

function ENT:UpdateTransmitState()
	return TRANSMIT_PVS
end

function ENT:Think()
	for ply, panel in pairs(self.players) do
		if ply and ply:IsValid() and ply:Alive() and (ply:GetShootPos() - self.Entity:GetPos()):Length() < 100 then
			if panel == 1 then
				if ply:Health() < 100 then
					ply:SetHealth(ply:Health() + 1)
				else
					panel = nil
				end
			else
				if GF.rounds[GF.round].weapons == GF.WEAPONS_FIGHTING then
					local weap1 = ply:GetPrimaryWeapon()
					local weap2 = ply:GetSecondaryWeapon()
				
					local ammoType1 = weap1.Primary.Ammo
					local ammoType2 = weap2.Primary.Ammo
					
					local maxAmmo1 = (weap1.Primary.ClipSize or 10) * 2
					local maxAmmo2 = (weap2.Primary.ClipSize or 10) * 2
					
					local filling = false
					if ply:GetAmmoCount(ammoType1) < maxAmmo1 then
						ply:GiveAmmo(1, ammoType1)
						filling = true
					end
					if ply:GetAmmoCount(ammoType2) < maxAmmo2 then
						ply:GiveAmmo(1, ammoType2)
						filling = true
					end
					
					if !filling then
						panel = nil
					end
				else
					panel = nil
				end
			end
		else
			panel = nil
		end
		self.players[ply] = panel
	end
end

function ENT:Use(ply)
	if ply:Team() == self.Entity:GetSkin() then
		local cursor = self:Cursor(ply)
		if cursor.onPanel then
			self.players[ply] = cursor.onPanel
		end
	end
end

--[[
function ENT:Think()
	for ply, type in pairs(self.leeches) do
		if ply:Alive() and (ply:GetShootPos() - self.Entity:GetPos()):Length() < 64 then
			if type == 1 then
				if ply:Health() < 100 then
					ply:SetHealth(ply:Health() + 1)
				elseif ply:Armor() < 100 then
					ply:SetArmor(ply:Armor() + 1)
				else
					self.leeches[ply] = nil
				end
			elseif type == 2 then
				if GF.rounds[GF.round].weapons == GF.WEAPONS_FIGHTING then
					primaryAmmo = ply.gf.primary.Primary.Ammo
					secondaryAmmo = ply.gf.secondary.Primary.Ammo
					if ply:GetAmmoCount(primaryAmmo) < 50 then
						ply:GiveAmmo(1, primaryAmmo)
					elseif ply:GetAmmoCount(secondaryAmmo) < 50 then
						ply:GiveAmmo(1, secondaryAmmo)
					else
						self.leeches[ply] = nil
					end
				end
			end
		else
			self.leeches[ply] = nil
		end
	end
end
]]
